package com.bjtu.literatureclient.dao.category;

import com.bjtu.literatureclient.domain.base.BaseModel;
import com.bjtu.literatureclient.domain.category.SubsetIndexNo;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
*@author LMR
*@data 2018年1月30日下午8:23:34
*/
@Mapper
public interface ICategoryDao {

	 @Select("<script>select distinct UserNo, SubsetNo,SubsetTitle FROM subsetindexnotable WHERE UserNo=#{userNo} </script>")
	 List<SubsetIndexNo> queryCategory(String userNo);
	 
	 
	 @Select("<script>SELECT  DISTINCT major FROM subsetindexnotable WHERE 1=1\n" +
	            "<if test=\"SubsetTitle!=null and SubsetTitle!=''\">\n" +
	            "AND SubsetTitle=#{categoryName}\n" +
	            "</if>"  +
	            "</script>")
	 List<SubsetIndexNo> queryMajor(BaseModel model);

	@Select("<script>SELECT  SubsetNo FROM subsetindexnotable WHERE UserNo=#{userNo}  order by SubsetNo asc</script>")
	List<Integer> queryNewSubsetNo(String userNo);

	@Insert("<script> INSERT INTO subsetindexnotable (UserNo,SubsetNo, IndexNo,SubsetTitle,SubsetDate)" +
			" VALUES (#{userNo},#{subsetNo},#{indexNo},#{subsetTitle},#{subsetDate})</script>")
	int addNewCategory(@Param("userNo") String userNo, @Param("indexNo") String indexno, @Param("subsetNo") String subsetNo, @Param("subsetTitle") String subsetTitle, @Param("subsetDate") String subsetDate);

	@Select("<script>SELECT IndexNo FROM subsetindexnotable WHERE UserNo=#{userNo} AND SubsetNo=#{subsetNo}</script>")
	List<String> queryBySubSetNo(@Param("userNo") String userNo, @Param("subsetNo") String subsetNo);

	@Select("<script>SELECT  * FROM subsetindexnotable WHERE UserNo=#{userNo} </script>")
	List<SubsetIndexNo> querySubsetByUser(String userNo);

	@Delete("<script>DELETE FROM subsetindexnotable WHERE UserNo=#{userNo} AND IndexNo=#{indexNo}</script>")
	void deletesubsetIndexNo(@Param("userNo") String userNo, @Param("indexNo") String indexNo);

	@Delete("<script>DELETE FROM subsetindexnotable WHERE UserNo=#{userNo} AND SubsetNo=#{subsetNo}</script>")
    boolean deleteCategory(@Param("userNo") String userNo, @Param("subsetNo") String subsetNo);

	@Select("<script>SELECT  SubsetTitle FROM subsetindexnotable WHERE UserNo=#{userNo} AND SubsetNo=#{subsetNo} </script>")
	List<String> querySubsetTitle(@Param("userNo") String userNo, @Param("subsetNo") String subsetNo);

	@Select("<script>SELECT  SubsetTitle FROM subsetindexnotable WHERE UserNo=#{userNo} </script>")
	List<String> queryTitleByUserNo(String userNo);

	@Delete("<script>DELETE FROM subsetindexnotable WHERE UserNo=#{userNo} AND indexNo=#{indexNo} AND SubsetNo=#{subsetNo}</script>")
	boolean deletePaperFromGroup(@Param("userNo") String userNo, @Param("indexNo") String indexNo, @Param("subsetNo") String subsetNo);
}
